﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CWB.Web.MVC.BaseController;
using CWB.Common.Logging;
using CWB.Web.Models.Configuration;
using CWB.Common.Constant;
using CWB.Web.MVC.Filters;
using CWB.Web.DB;
using CWB.Common.Utilities;

namespace CWB.WebSite.Controllers
{
    [PermissionFilterAttvibute(loginType = LoginType.Bo)]
    public class SentenceController : MultiCultureBaseController
    {
        private static readonly ISysLog Log = SysLog.GetLogger(typeof(BouController));

        public SentenceController(LanguageInfo languageInfo)
            : base(languageInfo)
        {
            ControllerPermision = Permission.Private;
        }

        public ActionResult Index()
        {
            ViewData["Categorys"] = getAllCategoryData();
            return View();
        }

        public ActionResult Create()
        {
            ViewData["Categorys"] = getAllCategoryData();
            return View();
        }

        private List<DbModelCategorySentence> getAllCategoryData()
        {
            DbTableCategorySentence odb = new DbTableCategorySentence();
            List<DbModelCategorySentence> category = odb.getAllData();
            return category;
        }

        public ActionResult CategoryCreateing()
        {
            return View();
        }

        [NoClientCacheFilter]
        public ActionResult Update(int id)
        {
            ViewData["Categorys"] = getAllCategoryData();
            DbModelSentence model = new DbModelSentence() { };

            ViewData["sn"] = id;
            DbTableSentence odb = new DbTableSentence();
            int sn = Convert.ToInt32(id);
            try
            {
                model = odb.getDataBySn(id);
                ViewData["error"] = "";
            }
            catch
            {
                ViewData["error"] = Localization.TrandlateMessage(Err.TheBackOfficeUserIsNotExist);
            }
            return View(model);
        }

        [NoClientCacheFilter]
        public ActionResult CategoryUpdate(int id)
        {
            DbModelCategorySentence model = new DbModelCategorySentence();

            ViewData["sn"] = id;
            DbTableCategorySentence odb = new DbTableCategorySentence();
            int sn = Convert.ToInt32(id);
            try
            {
                model = odb.getDataBySn(id);
                ViewData["error"] = "";
            }
            catch
            {
                ViewData["error"] = Localization.TrandlateMessage(Err.TheBackOfficeUserIsNotExist);
            }
            return View(model);
        }




        public ActionResult CategoryIndex()
        {
            return View();
        }

    }
}
